﻿using MediatR;
using Traceability.APP.Application.Command.Company;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Company
{
    /// <summary>
    /// 屠宰企业的显示
    /// </summary>
    public class ShowCompanyCommandHandle:IRequestHandler<ShowCompanyCommand,APIResult<List<Company_Model>>>
    {
        private readonly IBaseRepository<Company_Model> CompanyDal;

        public ShowCompanyCommandHandle(IBaseRepository<Company_Model> companyDal)
        {
            CompanyDal = companyDal;
        }

        public Task<APIResult<List<Company_Model>>> Handle(ShowCompanyCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Company_Model>> result = new APIResult<List<Company_Model>>();
            var list = CompanyDal.GetAll().Where(x => x.Batch == request.Batch && x.IsDeleted == false);
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }


    }
}
